package com.wuhanins.insmytestdemo.base;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewbinding.ViewBinding;

import com.wuhanins.common.utils.INSLog;
import com.wuhanins.insmytestdemo.BuildConfig;
import com.wuhanins.insmytestdemo.R;
import com.wuhanins.zero2.view.ZeroViewBindingActivity;

/**
 * Author  ： logan
 * Time    ： 10/12/21 3:11 PM
 * Desc    ：
 */
public abstract class BaseActivity<T extends ViewBinding> extends ZeroViewBindingActivity<T> {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (BuildConfig.DEBUG) {
            INSLog.e("Activity监控", this.getLocalClassName());
        }
    }

    /**
     * 设置点击监听器
     *
     * @param listener
     */
    public void setOnClickListener(View.OnClickListener listener) {
        LinearLayout layout = (LinearLayout) findViewById(R.id.layout_top);
        LinearLayout optionsButton = (LinearLayout) layout.findViewById(R.id.btn_activity_options);
        optionsButton.setOnClickListener(listener);
    }

    public void closeSoftInput() {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null && imm.isActive()) {
            if (this.getCurrentFocus() != null)
                imm.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

    /**
     * 回退事件
     *
     * @param v
     */
    public void onBack(View v) {
        onBackPressed();
    }
}
